library(tidyverse)
library(readxl)
path = "files/2025-07-06/Challenge 38.xlsx"
input = read_excel(path, range = "B2:D11")
test = read_excel(path, range = "F2:H8")
result = input %>%
summarise(n = n_distinct(Product),
Product = paste0(Product, collapse = ", "),
.by = c(Date,Store)) %>%
mutate(lag = lag(n, default = 0), .by = Store) %>%
select(Date, Store, Product = lag)
all.equal(result, test, check.attributes = FALSE)
#> [1] TRUECrispo - Excel Challenge 27 2025
excel-challenges
weekly-exercises
Easy Sunday Excel Challenge

Challenge Description
Easy Sunday Excel Challenge
⭐ ⭐Count should be per Store per Day
Solutions
Logic:
Reads the workbook range needed for the challenge
Aggregates or ranks values at the correct grouping level
Builds the intermediate helper columns that drive the final answer
Strengths:
- The R solution stays compact and mirrors the workbook logic closely.
Areas for Improvement:
- The code assumes the workbook layout and named ranges remain stable.
Gem:
- The best part of the solution is choosing a tidy intermediate shape before producing the final answer.
import pandas as pd
path = "files/2025-07-06/Challenge 38.xlsx"
input = pd.read_excel(path, usecols="B:D", skiprows=1, nrows=10)
test = pd.read_excel(path, usecols="F:H", skiprows=1, nrows=6).rename(columns=lambda col: col.replace('.1', ''))
result = (
input.groupby(['Date', 'Store'], as_index=False)
.agg(n=('Product', 'nunique'))
)
result['Product'] = result.groupby('Store')['n'].shift(1, fill_value=0)
result = result[['Date', 'Store', 'Product']]
print(result.equals(test))Logic:
Reads the workbook range needed for the challenge
Aggregates or ranks values at the correct grouping level
Strengths:
- The Python version keeps the same rule in a direct pandas-oriented workflow.
Areas for Improvement:
- As with the R version, any workbook layout change would require small adjustments.
Gem:
- The implementation stays close to the stated challenge instead of adding unnecessary complexity.
Difficulty Level
This task is easy to moderate:
- The business rule is readable, but the workbook still needs a few careful transformation steps.